#ifndef GPUBLIC_H
#define GPUBLIC_H

#include <QString>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef unsigned char uint8_t;
typedef unsigned char byte;
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned int u32;

#ifdef BOOL
#undef BOOL
#endif
typedef int BOOL;
typedef char s8;
typedef short s16;
typedef int s32;

#define getarraylen(array) (int)(sizeof(array) / sizeof(array[0]))

#define unsed(A)                                                               \
  do {                                                                         \
    (void)(A);                                                                 \
  } while (0)

#define true 1
#define false 0

/* 定义软件版本号 */
#define v_major 1    /* 主版本号 0~15 */
#define v_minor 1    /* 从版本号 0~127 */
#define v_revision 0 /* 修订版本 15 bit位 */
#define v_reserve 0  /* 保留  0~63*/

/* 定义打印等级 测试使用 */
#define debugLv2 1

#define logInfo printf

#ifdef debugLv1
#define logDebug(format, ...) printf(format, ##__VA_ARGS__)
#elif debugLv2
#define logDebug(format, ...)                                                  \
  (printf("%s[%d]: ", __FILE__, __LINE__), printf(format, ##__VA_ARGS__))
#elif debugLv3
#define logDebug(format, ...)                                                  \
  (printf("%s[%d]-<%s>: ", __FILE__, __LINE__, __FUNCTION__),                  \
   printf(format, ##__VA_ARGS__))
#endif

#define logDebugArray(array, len)                                              \
  do {                                                                         \
    int __i;                                                                   \
    for (__i = 0; __i < (len); ++__i)                                          \
      logInfo("%02X ", ((u8 *)(array))[__i]);                                  \
  } while (0)
#define logDebugArrayEx(note, array, len)                                      \
  do {                                                                         \
    logDebug("%s[%d]: ", note, len);                                           \
    logDebugArray(array, len);                                                 \
    logInfo("\n");                                                             \
  } while (0)

/* 字节序调换 */
#define BSWAP_8(x) ((x)&0xff)
#define BSWAP_16(x) ((BSWAP_8(x) << 8) | BSWAP_8((x) >> 8))
#define BSWAP_32(x) ((BSWAP_16(x) << 16) | BSWAP_16((x) >> 16))
#define BSWAP_64(x) ((BSWAP_32(x) << 32) | BSWAP_32((x) >> 32))

/* 内存管理相关函数 */
#define GQ_IOT_Malloc malloc
#define GQ_IOT_free free
#define GQ_IOT_Memcpy memcpy
#define GQ_IOT_Memmove memmove
#define GQ_IOT_Memcmp memcmp
#define GQ_IOT_Memset memset

static QString version = "v1.0.0A";

#endif // GPUBLIC_H
